package configuration;

import exceptions.ExceptionWrongParameterClass;
import genetic.Genetic;
import genetic.GeneticRNA;

import java.io.IOException;
import java.util.ArrayList;

import mutationMethods.Mutator;

import objectiveFunctions.GeneticFitnessFunction;

import crossingMethods.Reproductor;


import replacementMethods.Replacement;
import selectionMethods.Selector;
import stoppingCriteria.GeneticStoppingCriterion;

public class EnvironmentGenetic extends Environment {

	ConfigGeneticNR config;
	Genetic alg;
	
	
	public EnvironmentGenetic(String configFile) throws IOException, ExceptionWrongParameterClass {
		initEnvironment(configFile);
	}
		
		
	@Override
	public ArrayList<TestData> loadConfigurationDataTest(String trainingFile) {return null;	}

	@Override
	public void loadConfigurationData() {
		
		// TODO Auto-generated method stub
	}

	
	@Override
	protected void initEnvironment(String configurationFile) throws IOException, ExceptionWrongParameterClass {
		config = ConfigGeneticNR.getInstance(configurationFile);
		int populationSize = config.getPopulationSize();
		double mutationRate = config.getMutationProbability();
		double crossingRate = config.getCrossProbability();
		String chromosomeRepresentation = config.getChromosomeRepresentation();
		Selector selectionStrategy = config.getSelectionStrategy();
		String populationStrategy = config.getPopulationStrategy();
		Replacement replacementStrategy = config.getReplacementStrategy();
		Reproductor reproductionStrategy = config.getReproductionStrategy();
		Mutator mutatorStrategy = config.getMutatorStrategy();
		int geneSize = config.getGeneSize();
		GeneticStoppingCriterion geneticStoppingCriteria = config.getGeneticStoppingCriteria();
		//double low= config.getLowerRange();
		//double top = config.getTopRange();
		double valueStopCriteria = config.getValueStopCriteria();
		GeneticFitnessFunction fitnessFunction = config.getGeneticFitnessFunction();
		int chromosomeSize = config.getChromosomeSize();
		double lowerRange=config.getLowerRange();
		double topRange =config.getTopRange();
		alg = new Genetic(populationSize,chromosomeSize,geneSize,mutationRate,crossingRate,chromosomeRepresentation,populationStrategy,
				selectionStrategy,reproductionStrategy,mutatorStrategy,geneticStoppingCriteria,valueStopCriteria,lowerRange,topRange,
				fitnessFunction,replacementStrategy);
	}
	
	public void runSolution() throws IOException, ExceptionWrongParameterClass
	{
		this.alg.runAlgorithm();
	}
	
	@Override
	protected void initEnvironment(String configurationFile, String trainingFile)
			throws IOException {
		// TODO Auto-generated method stub
		
	}

	

}
